#include <iostream>
#include <string>
#include <vector>
#include <cmath>

std::vector<std::string> split(const std::string &s) {
    std::vector<std::string> result;
    std::string word;
    for (char c : s) {
        if (c != ' ') {
            word += c;
        } else {
            result.push_back(word);
            word.clear();
        }
    }
    result.push_back(word);

    return result;
}

bool isPrime(int num) {
    if (num < 2) return false;
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0) return false;
    }
    return true;
}

int findClosestPrime(const std::string &input) {
    std::vector<std::string> words = split(input);
    if (words.size() != 3) {
        return -1;
    }

    std::vector<std::string> numStrings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int number = 0;
    for (const std::string &word : words) {
        int digit = -1;
        for (int i = 0; i < numStrings.size(); ++i) {
            if (word == numStrings[i]) {
                digit = i;
                break;
            }
        }
        if (digit == -1) {
            return -1;
        }
        number = number * 10 + digit;
    }

    if (number < 100 || number > 999) {
        return -1;
    }

    int lower = number - 1;
    int upper = number + 1;

    while (true) {
        if (isPrime(lower)) {
            return lower;
        }
        if (isPrime(upper)) {
            return upper;
        }
        lower--;
        upper++;
    }
}

int main() {
    std::string input;
    std::getline(std::cin, input);

    int result = findClosestPrime(input);
    if (result == -1) {
        std::cout << "Wrong input\n";
    } else {
        std::cout << result << std::endl;
    }

    return 0;
}
